// inventory.cpp : contains the definition for the inventory component, which
// allows an object to hold other objects, as well as money :)
//$Id: Inventory.cpp 41 2009-09-08 20:20:22Z brwarner2 $

#include "stdafx.h"

#include "Inventory.h"
#include "GameMonkey.h"
#include "ObjectManager.h"

void CInventory::Init(const ParameterList &params)
{
	//Check if money exists
	if( params.find("money") == params.end() ) m_nMoney = 0;
	else try { m_nMoney = boost::lexical_cast<unsigned int>(params.find("money")->second); }
	catch(...) { m_nMoney = 0; }
}

int CInventory::GMCall(gmThread* a_thread, const std::string& name)
{
	if( name == "GetMoney" )
	{
		GM_CHECK_NUM_PARAMS(0);
		a_thread->PushInt(m_nMoney);
		return GM_OK;
	}
	else if( name == "AddMoney" )
	{
		GM_CHECK_NUM_PARAMS(1);
		GM_CHECK_INT_PARAM( m, 0 );
		m_nMoney += m;
		return GM_OK;
	}
	return GM_EXCEPTION;
}

void CInventory::Message( MessageID message, const boost::any &arg )
{
}

void CInventory::RegisterGM(gmMachine *pGM)
{
	//Get object manager
	CObjectManager* pOM = GetGlobalObjectManager(*pGM);

	//Register money functions
	pOM->RegisterMemberFunction(COMPONENT_ID, "GetMoney");
	pOM->RegisterMemberFunction(COMPONENT_ID, "AddMoney");

}